﻿using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using SergeyPravodelov.Practice.BookStore.Data.Contexts;

namespace SergeyPravodelov.Practice.BookStore
{
    public class BookStoreMvcApplication : HttpApplication
    {
        public static readonly IContext DataContext;

        static BookStoreMvcApplication()
        {
            DataContext = new InMemoryDataContext();
        }

        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapRoute(
                "Default",
                "{controller}/{action}/{id}",
                new {controller = "Default", action = "Index", id = UrlParameter.Optional} // Parameter defaults
                );
        }

        protected void Application_Start()
        {   
            ValueProviderFactories.Factories.Add(new JsonValueProviderFactory());
            AreaRegistration.RegisterAllAreas();
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }
}